//
//  XMNotifiSetView.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/5/21.
//

#import "XMNotifiSetView.h"
#import "XMPrivacySetTypeTwoCell.h"

@interface XMNotifiSetView ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) NSArray *titleArr;

@end

@implementation XMNotifiSetView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    [self addSubview:self.navView];
    self.navTitleLabel.text = @"通知设置";
    
    _titleArr = @[@[@"赞和收藏", @"新增关注", @"评论", @"@", @"私信"], @[@"声音", @"震动"]];
    UITableView *tbl = [[UITableView alloc] initWithFrame:CGRectMake(0, kNavagationBarH, self.width, self.height - kNavagationBarH)];
    tbl.delegate = self;
    tbl.dataSource = self;
    tbl.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    tbl.separatorColor = kColorHEX(0xF1F1F1);
    tbl.backgroundColor = kColorHEX(0xF0F0F0);
    [tbl registerClass:[XMPrivacySetTypeTwoCell class] forCellReuseIdentifier:@"XMPrivacySetTypeTwoCellName"];
    if (@available(iOS 15.0, *)) {
        tbl.sectionHeaderTopPadding = 0;
    } else {
        tbl.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        // Fallback on earlier versions
    }
    [self addSubview:tbl];
    
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, KScaleWidth(102.0))];
    headView.backgroundColor = kColorHEX(0xffffff);
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(16.0), KScaleWidth(17.0), headView.width - KScaleWidth(16.0), KScaleWidth(24.0)) font:KFontSize(17.0) textColor:kColorHEX(0x333333)];
    titleLabel.text = @"消息通知已关闭";
    [headView addSubview:titleLabel];
    
    UILabel *explainLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(16.0), titleLabel.maxY, headView.width - KScaleWidth(16.0) - KScaleWidth(60.0), KScaleWidth(46.0)) font:KFontSize(13.0) textColor:kColorHEX(0x999999)];
    explainLabel.text = @"你已在系统中关闭通知，点击【去开启】前往系统设置-通知中，打开【允许通知】";
    [headView addSubview:explainLabel];
    
    UIButton *goOpenBtn = [UIButton buttonWithType:UIButtonTypeCustom font:KFontSize(15.0) frame:CGRectMake(headView.width - KScaleWidth(90.0), KScaleWidth(15.0), KScaleWidth(90.0), KScaleWidth(34.0)) title:@"去开启" titleColor:kColorHEX(0xDD4B39) image:@"mine_detail_icon"];
    [goOpenBtn addTarget:self action:@selector(goOpenAction:) forControlEvents:UIControlEventTouchUpInside];
    [goOpenBtn layoutButtonWithEdgeInsetsStyle:CSButtonEdgeInsetsStyleRight ImageTitleSpace:KScaleWidth(4.0)];
    [headView addSubview:goOpenBtn];
    tbl.tableHeaderView = headView;
}

//去开启
- (void)goOpenAction:(UIButton *)button {
    
}

#pragma mark - Delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _titleArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSArray *titleSubArr = _titleArr[section];
    return titleSubArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return KScaleWidth(8.0);
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.width, KScaleWidth(8.0))];
    headView.backgroundColor = kColorHEX(0xF0F0F0);
    return headView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return KScaleWidth(45.0);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    XMPrivacySetTypeTwoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"XMPrivacySetTypeTwoCellName" forIndexPath:indexPath];
    [cell setContentWithTitle:_titleArr[indexPath.section][indexPath.row] subTitle:@"" type:0];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
